package gof_002_结构型_Structural.gof_001_代理_Proxy.gof_003_DynamicProxy.g_1_jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 经纪人
 */
public class Agent implements InvocationHandler {
    private Object obj;

    public Agent(Object obj) {
        this.obj = obj;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        connection();       //联系
        bargain();          //讨价还价
        payEarnestMoney();  //支付订金

        method.invoke(obj, args);

        payBalanceDue();    //支付尾款
        return null;
    }

    /**
     * 经纪人的杂活累活
     */
    private void connection() {
        System.out.println("经纪人在联系...");
    }
    private void bargain() {
        System.out.println("经纪人在讨价还价...");
    }
    private void payEarnestMoney() {
        System.out.println("经纪人在支付订金...");
    }
    private void payBalanceDue() {
        System.out.println("经纪人在支付尾款...");
    }
}